package com.object.configuration.rabbitmq;

import com.common.rabitmq.RabbitmqName;
import com.rabbitmq.client.AMQP;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

//绑定延迟对了主要是处理和订单有关的
@Component
@Slf4j
public class DelayQueueOrder {
    //声明我们的交换机
    private String DelayExchangeName="delay_change";


     //创建延迟交换机
    @Bean
    CustomExchange delayExchange(){
        Map<String,Object> map= new HashMap<>();
       map.put("x-delayed-type","direct");
       return new CustomExchange(DelayExchangeName,"x-delayed-message",true,false,map);
    }
    //创建 队列
    @Bean
    Queue delayQueue(){
         return new Queue(RabbitmqName.RAPID_ORDER,true,false,false);
    }

    //队列与我们的交换机绑定
    @Bean
    Binding delayBinding(){
        return BindingBuilder
                .bind(delayQueue())
                .to(delayExchange())
                .with(RabbitmqName.RAPID_ORDER_ROUTING_KEY)
                .noargs();
    }



}
